<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        管理
        <small>列表</small>
    </h1>
</section>

<!-- Main content -->
<section class="content" id="curriculum-class-app">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-responsive table-striped table-bordered">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>名称</th>
                    <th>排序</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="item in list">
                    <td>{{item.class_id}}</td>
                    <td><input v-model="item.class_name" placeholder="输入名称..."></td>
                    <td><input v-model="item.class_sort"></td>
                    <td>
                        <a class="btn btn-primary btn-xs" @click="save(item)">保存</a>
                        <a class="btn btn-danger btn-xs" @click="del(item)">删除</a>
                    </td>
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="100">
                        <pagination :total="page.total" :limit="page.limit" :offset="page.offset" @turn="turnPage" ></pagination>
                    </td>
                </tr>
                <tr>
                    <td colspan="100">
                        <a class="btn btn-default" @click="getList">刷新</a>
                        <a class="btn btn-info" @click="add">添加</a>
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>
</section>
<!-- /.content -->

<script>
    var curriculum_class_app = new Vue({
        el: '#curriculum-class-app',
        data: {
            list: [],
            page: {
                total: 0,
                limit: 10,
                offset: 0,
                category: 3
            }
        },
        created: function () {
            this.getList();
        },
        methods: {
            getList: function () {
                ajax({
                    uri: '/curriculum/class_list',
                    data: this.page,
                    success: function(resp){
                        this.list = resp.list;
                        this.page.total = resp.total;
                    }.bind(this)
                });
            },
            add: function () {
                this.list.push({class_sort: 255})
            },
            save: function (item) {
                ajax({
                    uri: '/curriculum/class_save',
                    data: item,
                    success: function(resp){
                        this.getList();
                    }.bind(this)
                });
            },
            del: function (item) {
                if (confirm('确定要删除吗？') === false) return;
                ajax({
                    uri: '/curriculum/class_del',
                    data: {class_id: item.class_id},
                    success: function (resp) {
                        this.getList();
                    }.bind(this)
                })
            },
            turnPage: function (offset) {
                this.page.offset = offset;
            }
        },
        watch: {
            'page.offset': function (nv, ov) {
                this.getList();
            }
        }
    })
</script>